<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>同花顺概念</title>		
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<style type="text/css">
        .res
        {
            color: Red;
        }
		.result{
			background: Yellow;
		}
		.fixedBox::-webkit-scrollbar {
				width: 12px;     
				height: 12px;				
		}		
		</style>
	</head>
	<body>
		<div id="towrite1" class="fixedBox"></div>		
		<div id="towrite2" class="fixedBox"></div>		
		<script>
			window.onload = function() {
			var obj1 = document.getElementById("towrite1");			  					
			var div_child ='<div id="towrite3"><input id="key" type="text" style="width: 120px;"/><input type="button" value="下一个" onclick="next()" /><input type="button" value="上一个" onclick="previous()" /></div>';
			obj1.innerHTML = div_child;
			changeStyle();			
			getSource1();			
			setTimeout("getSource3()","3000"); 			
			}
			
			window.onresize = function() {
			 changeStyle();	
			}
					
			function time_range(beginTime, endTime) {
				var strb = beginTime.split(":");
				if (strb.length != 2) {
					return false;
				}

				var stre = endTime.split(":");
				if (stre.length != 2) {
					return false;
				}

				var b = new Date();
				var e = new Date();
				var n = new Date();

				b.setHours(strb[0]);
				b.setMinutes(strb[1]);
				e.setHours(stre[0]);
				e.setMinutes(stre[1]);

				if (n.getTime() - b.getTime() > 0 && n.getTime() - e.getTime() < 0) {
					getSource2();					
					console.log(true)　　　　　　
					return true;				
				} else {
					console.log(false)
				    return false;     
				}
			}　　　
   　　　
			$(function() {
				setInterval(function() {
				time_range("9:00","15:15")						
				},
				60000);
			})
			
			function changeStyle() {
				var obj1 = document.getElementById("towrite1");			  
				obj1.style.top= "0px";
				obj1.style.left="0px";				  		  
				obj1.style.width= '50%';
				obj1.style.height= "100%";				
				
				var obj2 = document.getElementById("towrite2");			  
				obj2.style.top= "0px";
				obj2.style.left= obj1.offsetLeft + obj1.offsetWidth + 'px';			  		  
				obj2.style.width= "48%";
				obj2.style.height= "100%";		
								
				var obj3 = document.getElementById("towrite3");
				obj3.style.position= "fixed";
				obj3.style.top= "2px";
				obj3.style.left= obj1.offsetLeft + obj1.offsetWidth - 260 + 'px';					
			}
			
			
				Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};
			
			
			function createXmlHttp1() {
				if (window.XMLHttpRequest) {
				xmlHttp1 = new XMLHttpRequest();				
				} else {
				xmlHttp1 = new ActiveXObject("Microsoft.XMLHTTP");				
				}
			}
			
			function createXmlHttp2() {
				if (window.XMLHttpRequest) {				
				xmlHttp2 = new XMLHttpRequest();
				} else {				
				xmlHttp2 = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
			
			function createXmlHttp3() {
				if (window.XMLHttpRequest) {				
				xmlHttp3 = new XMLHttpRequest();
				} else {				
				xmlHttp3 = new ActiveXObject("Microsoft.XMLHTTP");
				}
			}
						
			
			function getSource1() {	    				
				var url1 = "龙头股1.json"; 
				createXmlHttp1();
				xmlHttp1.onreadystatechange = writeSource1;
				xmlHttp1.open("GET", url1, true);
				xmlHttp1.send(null);
				}
				
			function getSource3() {	    				
				var url3 = "龙头股2.json"; 
				createXmlHttp3();
				xmlHttp3.onreadystatechange = writeSource3
				xmlHttp3.open("GET", url3, true);
				xmlHttp3.send(null);
				}
				
			function getSource2(dm) {	
				var url2 = "http://basic.10jqka.com.cn/48/" + dm + "/"; 
				createXmlHttp2();
				xmlHttp2.onreadystatechange = writeSource2;
				xmlHttp2.open("GET", url2, true);
				xmlHttp2.send(null);
				}
				
			function update(ss) {
				//alert(ss);
				var dms=ss.split('#');
				dm = dms[0];
				bk = dms[1];				
				<!-- $('#key').val(dm);	 -->
				<!-- next(); -->
				
				div = document.getElementById('towrite2');				
				div.innerHTML = '<h3>' + bk + '</h3>';					
				getSource2(dm);
				}
			
			function update1(ss) {
				//alert(ss);
				var dms=ss.split('#');
				dm = dms[0];
				//bk = dms[1];	
				//gpdm = dms[2];
				//update(ss);				
				$('#key').val(dm);	
				next1();														
				}
				
			function writeSource1() { 
				if (xmlHttp1.readyState == 4) {         
					var data = xmlHttp1.responseText
					//alert(data);
					//document.write(data);					
					var transform_aa = [           
					{"tag":"ul", children:function(){return(json2html.transform(this.datas, transform_bb));}}
					];
					
					var code;
					var transform_bb= 
					{"tag":"p", children:[					
					{"tag": "h3", "html":"<a href='javascript:void(0);' onclick='update(\"${概念代码}\"+\"#\"+\"${概念名称}\"+\"#\"+\"0\");'>${概念代码}&nbsp;&nbsp;${概念名称}</a>"}, 											
					//{"tag": "h3", "html":"${概念代码}&nbsp;&nbsp;${概念名称}"}, 
					{"tag":"ul", children:[
					{"tag": "p", "html":"${概念解析}"},  
					{"tag": "b", "html":"龙头股："}, 					
					{"tag":"ul", children:function(){return(json2html.transform(this.龙头股, transform_cc));}}    				
					]}]};
					
					var transform_cc= 
					{"tag":"li", children:[					   
					//{"tag": "p", "html":"<a href='http://www.treeid/code_${股票代码}' >${股票代码}&nbsp;&nbsp;${股票名称} </a>"},
					{"tag": "p", "html":"<a href='javascript:void(0);' onclick='update1(\"${股票代码}\"+\"#\"+\"${股票名称}\");'>${股票代码}&nbsp;&nbsp;${股票名称}</a>"},					
					//{"tag": "p", "html":"${股票详情}"},  
					]};   
					
					var html = json2html.transform(data, transform_aa);					
					div=document.getElementById('towrite1');
					div.innerHTML += '<h2>同花顺概念</h2>' + html;
					$("div a:first").click();					
				}
			}
			
			function writeSource3() { 
				if (xmlHttp3.readyState == 4) {         
					var data = xmlHttp3.responseText
					//alert(data);
					//document.write(data);
					
					var transform_aa = [           
					{"tag":"ul", children:function(){return(json2html.transform(this.datas, transform_bb));}}
					];
					
					var transform_bb= 
					{"tag":"p", children:[
					{"tag": "h3", "html":"<a href='javascript:void(0);' onclick='update(\"${概念代码}\"+\"#\"+\"${概念名称}\");'>${概念代码}&nbsp;&nbsp;${概念名称}</a>"}, 											
					//{"tag": "h3", "html":"${概念代码}&nbsp;&nbsp;${概念名称}"}, 
					{"tag":"ul", children:[
					{"tag": "p", "html":"${概念解析}"},    									
					{"tag": "b", "html":"龙头股："}, 					
					{"tag":"ul", children:function(){return(json2html.transform(this.龙头股, transform_cc));}}    				
					]}]};
					
					var transform_cc= 
					{"tag":"li", children:[					   
					//{"tag": "p", "html":"<a href='http://www.treeid/code_${股票代码}' >${股票代码}&nbsp;&nbsp;${股票名称} </a>"},
					{"tag": "p", "html":"<a href='javascript:void(0);' onclick='update1(\"${股票代码}\"+\"#\"+\"${股票名称}\");'>${股票代码}&nbsp;&nbsp;${股票名称}</a>"},
					//{"tag": "p", "html":"${股票详情}"},  
					]};   
					
					var html = json2html.transform(data, transform_aa);					
					div = document.getElementById('towrite1');
					div.innerHTML += html;												
				}
			}
					
			function writeSource2() { 	
					if (xmlHttp2.readyState == 4) {  				
					var data = xmlHttp2.responseText					
					data = data.replace(/ /g,"").match(/\"listdata\"(\S*)\<\/div\>/)[1];
					data = ",[" + data.match(/\[\[(\S*)/)[1];  //f[
					data = data.replace(/\]\]\}\}\}/g,"],}]}");
					data = data.replace(/\<br\>/g,"").replace(/\",+(\d{1,2})+,\"/g,function(word){ str = word.match(/\",(\S*),\"/)[1]; return "\",\"" + str + "\",\"";}).replace(/&nbsp;/g,"");					
					data = data.replace(/(,\[).*?(?=\],)/g,function(word){ str = word.match(/,\[(\S*)/)[1]; return '{"code":' + str.split('\",\"')[0] + '","name":"' + str.split('\",\"')[1] + '","zt":"' + str.split('\",\"')[3] + '","xq":"'+str.split('\",\"')[7];});
					<!-- data = '{\"listdata\":[' + data.replace(/\]{/g,"},{").replace(/\],\}\]\}/g,"}]}"); -->
					data = "["+data.replace(/\]{/g,"},{").replace("],}]}","}]");
					//document.write(data);
					var result = JSON.parse(data); //JSON字符串转换为对象
					function up(a,b){
					  return b.zt-a.zt
					}
					result.sort(up);
					result = JSON.stringify( result );						
					data= '{\"listdata\":' + result + "}";
					//document.write(data);
					
					var transform_aa = [           
					{"tag":"ul", children:function(){return(json2html.transform(this.listdata, transform_bb));}}
					];
					
					var transform_bb= 
					{"tag":"li", children:[
					{"tag": "b", "html":"<a href='http://www.treeid/code_${code}' >${code}&nbsp;&nbsp;${name}&nbsp;&nbsp;涨停次数：${zt} </a>"},					
					{"tag": "p", "html":"${xq}"},    									
					]};
					
					var html = json2html.transform(data, transform_aa);					
					div = document.getElementById('towrite2');
					div.innerHTML += html;		
				}
			}
		</script>	
		
		<script>
			var oldKey = "";
			var index = -1;
			var pos = new Array();
			var oldCount = 0;

			function previous(){
			index--;
			index = index < 0 ? oldCount - 1 : index;
			search();
			}
			function next(){
			index++;
			//index = index == oldCount ? 0 : index;
			if(index==oldCount){
				index = 0 ;
			}
			search();
			}

			function search() {
				$(".result").removeClass("res");
				var key = $("#key").val(); 
				if (!key) {
					console.log("key为空则退出");
					$(".result").each(function () {
					$(this).replaceWith($(this).html());
					});
					oldKey = "";
					return; 
				}
				if (oldKey != key) {
					console.log("进入重置方法");
					//重置
					index = 0;					
					$(".result").each(function () {
					$(this).replaceWith($(this).html());
					});
					pos = new Array();
					var regExp = new RegExp(key+'(?!([^<]+)?>)', 'ig');//正则表达式匹配
					$("body").html($("body").html().replace(regExp, "<span id='result" + index + "' class='result'>" + key + "</span>")); // 高亮操作
					//$("#towrite1").html($("#towrite1").html().replace(regExp, "<span id='result" + index + "' class='result'>" + key + "</span>")); // 高亮操作
					$("#key").val(key);
					oldKey = key;
					$(".result").each(function () {
					pos.push($(this).offset().top);
					});
					oldCount = $(".result").length;
					console.log("oldCount值：",oldCount);
				}
			
				$(".result:eq(" + index + ")").addClass("res");
				$("#towrite1").scrollTop(pos[index] - 100);
			}
			
			var oldKey1 = "";
			var index1 = -1;
			var pos1 = new Array();
			var oldCount1 = 0;
			
			function previous1(){
				index1--;
				index1 = index1 < 0 ? oldCount1 - 1 : index1;
				search1();
			}
			function next1(){
				index1++;
				//index1 = index1 == oldCount1 ? 0 : index1;
				if(index1==oldCount1){
				index1 = 0 ;
			}
				search1();
			}
			
			function search1() {
				$(".result").removeClass("res");
				var key = $("#key").val(); 
				if (!key) {
					console.log("key为空则退出");
					$(".result").each(function () {
					$(this).replaceWith($(this).html());
					});
					oldKey1 = "";
					return; 
				}
				if (oldKey1 != key) {
					console.log("进入重置方法");
					//重置
					$("#towrite2").scrollTop(0);
					index1 = 0;
					$(".result").each(function () {
					$(this).replaceWith($(this).html());
					});
					pos1 = new Array();
					var regExp = new RegExp(key+'(?!([^<]+)?>)', 'ig');//正则表达式匹配
					//$("body").html($("body").html().replace(regExp, "<span id='result" + index1 + "' class='result'>" + key + "</span>")); // 高亮操作
					$("#towrite2").html($("#towrite2").html().replace(regExp, "<span id='result" + index1 + "' class='result'>" + key + "</span>")); // 高亮操作
					$("#key").val(key);
					oldKey1 = key;
					$(".result").each(function () {
					pos1.push($(this).offset().top);
					});
					oldCount1 = $(".result").length;
					console.log("oldCount1值：",oldCount1);
				}
				
				$(".result:eq(" + index1 + ")").addClass("res");
				$("#towrite2").scrollTop(pos1[index1] - 100);
			}
		</script>
			
	</body>

</html>